/*
 * core.h
 *
 *  Created on: Aug 3, 2009
 *      Author: jacky
 */

#ifndef CORE_H_
#define CORE_H_
#include "controllers/controller.h"
#include "views/view.h"

#define MAX_NAME_SIZE 256

#ifdef DEBUG
#define DEBUG_PRINTF(args...) do{\
	printf("<%s>",__FILE__);\
	printf(args);\
	}while(0)

#define DEBUG_ERROR(args...) do{\
	fprintf(stderr,"<%s>",__FILE__);\
	fprintf(stderr,args);\
	}while(0)

#define cgiError(args...) do{\
	fprintf(stdout, "Content-Type: text/html\r\n\r\n"); \
	fprintf(stdout,args);\
	exit(1);\
	}while(0)

#else
#define DEBUG_PRINTF(args...)
#define DEBUG_ERROR(args...)
#define cgiError(args...)
#endif /* DEBUG */

typedef enum
{
	CORE_OK = 0, CORE_FAIL, CORE_ERROR_CTLID, CORE_ERROR_ACTID,
} CoreStatus;

extern CoreStatus initRequest(HttpRequest *req, Controller *controllers,
		int controllersLength);
extern CoreStatus initResponse(HttpResponse *rsq);
extern void destoryResponse(HttpResponse *rsp);
extern void destoryRequest(HttpRequest *req);

extern int cgiMain();
extern struct timeval elapsed_time();
#ifdef DEBUG
extern void print4debug(const char* format, ...);
#else /* DEBUG */
#define print4debug(...)
#endif /* DEBUG */
#endif /* CORE_H_ */
